package com.kkd.kkdapp.activity;

import android.content.Context;
import android.content.Intent;
import android.graphics.Paint;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.kkd.kkdapp.R;
import com.kkd.kkdapp.base.BaseActivity;
import com.kkd.kkdapp.http.entity.BondTransferParData;
import com.kkd.kkdapp.listener.OnSingleClickListener;
import com.kkd.kkdapp.utils.AppUtil;
import com.kkd.kkdapp.utils.PreferenceUtils;
import com.nostra13.universalimageloader.core.ImageLoader;

public class FinishBeforeTenderActivity extends BaseActivity {

	private Context mContext = this;
	private boolean FLAG_FINISH = true;
	private View rel_content_1;
	private View rel_content_2;
	private ImageView iv_top;
	private TextView tv_toSuibian_content_1;
	private ImageView iv_reward_1;
	private ImageView iv_reward_2;
	private boolean isHaveNewTask;// 说明是否有新手任务
	private boolean isShowDialogTip;
	private int enterTypeFlag;
	private String title;
	private String surplus;
	private String yuebaoid;
	private long lowestAmount;
	private double rates;
	private String interests;
	private String url_xieYi;
	private String title_xieYi;
	private String bidId;
	private String bidTitle;
	private int bidPeriod;
	private long amountMultiple;
	private String bidPeriodType;
	private String bidInterest;
	private long bidFreeAmount;
	private long maxAmount;
	private long bidAmount;
	private long totalLixi;
	private String bidType;
	private String businessType;
	private int productType;
	private String bidPeriodWeb;
	private int bidPeriodAdd;
	private View close;
	private String json; // 债权转让详情

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_finish_before_tender);
		initView();
		getMessage();
	}

	private void initView() {
		close = findViewById(R.id.result_title_img);
		close.setOnClickListener(new OnSingleClickListener() {

			@Override
			public void onSingleClick(View v) {
				// toPre();
				finish();
			}
		});
		iv_top = (ImageView) findViewById(R.id.iv_top);
		rel_content_1 = findViewById(R.id.rel_content_1);
		rel_content_2 = findViewById(R.id.rel_content_2);
	}

	private String poi_pre_reward_image;
	private String poi_pre_reward_image2;

	private void getMessage() {
		Intent intent = getIntent();
		isHaveNewTask = intent.getBooleanExtra("isHaveNewTask", false);// 说明是否有新手任务
		isShowDialogTip = intent.getBooleanExtra("isShowDialogTip", false);
		enterTypeFlag = intent.getIntExtra("enterTypeFlag", -1);
		poi_pre_reward_image = getIntent().getStringExtra(
				"poi_pre_reward_image");
		poi_pre_reward_image2 = getIntent().getStringExtra(
				"poi_pre_reward_image2");
		if (enterTypeFlag == 4) {
			title = intent.getStringExtra("title");
			surplus = intent.getStringExtra("surplus");
			yuebaoid = intent.getStringExtra("yuebaoid");
			lowestAmount = intent.getLongExtra("lowestAmount", 0);
			rates = intent.getDoubleExtra("rates", 0);
			interests = intent.getStringExtra("interests");
			url_xieYi = intent.getStringExtra("url_xieYi");
			title_xieYi = intent.getStringExtra("title_xieYi");
		} else if (enterTypeFlag == 5) {
			bidId = intent.getStringExtra("bidId");
			bidTitle = intent.getStringExtra("bidTitle");
			bidPeriod = intent.getIntExtra("bidPeriod", 0);
			amountMultiple = intent.getLongExtra("amountMultiple", 0);
			lowestAmount = intent.getLongExtra("lowestAmount", 0);
			bidPeriodType = intent.getStringExtra("bidPeriodType");
			bidInterest = intent.getStringExtra("bidInterest");
			bidFreeAmount = intent.getLongExtra("bidFreeAmount", 0);
			maxAmount = intent.getLongExtra("maxAmount", 0);
			bidAmount = intent.getLongExtra("bidAmount", 0);
			totalLixi = intent.getLongExtra("totalLixi", 0);
			bidType = intent.getStringExtra("bidType");
			businessType = intent.getStringExtra("businessType");
			productType = intent.getIntExtra("productType", -1);
			bidPeriodWeb = intent.getStringExtra("bidPeriodWeb");
			bidPeriodAdd = intent.getIntExtra("bidPeriodAdd", 0);
		} else if (enterTypeFlag == 6) { // 债权转让购买
			json = intent.getStringExtra("json");
		}

		if (isHaveNewTask) {// 说明有新手任务
			if (!TextUtils.isEmpty(poi_pre_reward_image)
					&& !TextUtils.isEmpty(poi_pre_reward_image2)) {
				initHaveNewTask();
			} else {
				initNoNewTask();
			}
		} else {
			initNoNewTask();
		}
	}

	/*
	 * 新手任务
	 */
	private void initHaveNewTask() {
		rel_content_1.setVisibility(View.GONE);
		rel_content_2.setVisibility(View.VISIBLE);
		iv_reward_1 = (ImageView) findViewById(R.id.iv_reward_1);
		iv_reward_2 = (ImageView) findViewById(R.id.iv_reward_2);
		if (!TextUtils.isEmpty(poi_pre_reward_image)) {
			ImageLoader.getInstance().displayImage(poi_pre_reward_image,
					iv_reward_1, R.drawable.icon_beforetender_top);
		}
		if (!TextUtils.isEmpty(poi_pre_reward_image2)) {
			ImageLoader.getInstance().displayImage(poi_pre_reward_image2,
					iv_reward_2, R.drawable.icon_beforetender_bottom);
		}
		findViewById(R.id.tv_toRecharge_content_2).setOnClickListener(
				new OnSingleClickListener() {

					@Override
					public void onSingleClick(View v) {
						Intent intent = new Intent(mContext,
								RechargeActivity.class);
						startActivity(intent);
						finish();
					}
				});
	}

	/*
	 * 非新手任务
	 */
	private void initNoNewTask() {
		rel_content_1.setVisibility(View.VISIBLE);
		rel_content_2.setVisibility(View.GONE);
		// 跳转到充值
		findViewById(R.id.tv_toRecharge_content_1).setOnClickListener(
				new OnSingleClickListener() {

					@Override
					public void onSingleClick(View v) {
						Intent intent = new Intent(mContext,
								RechargeActivity.class);
						startActivity(intent);
						finish();
					}
				});
		// 随便逛逛
		tv_toSuibian_content_1 = (TextView) findViewById(R.id.tv_toSuibian_content_1);
		tv_toSuibian_content_1.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG); // 下划线
		tv_toSuibian_content_1.getPaint().setAntiAlias(true);// 抗锯齿
		tv_toSuibian_content_1.setOnClickListener(new OnSingleClickListener() {

			@Override
			public void onSingleClick(View v) {
				Intent intent = new Intent(mContext, HomeActivity.class);
				startActivity(intent);
				HomeActivity.mActivity.homeNavigation();
				finish();
			}
		});
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK) {
			// toPre();
			finish();
			return true;
		}
		return super.onKeyDown(keyCode, event);
	}

	public void toPre() {
		if (FLAG_FINISH) {
			FLAG_FINISH = false;
			Intent intent_toPre = null;
			if (enterTypeFlag == 4) {
				intent_toPre = new Intent(mContext, CurrentTenderActivity.class);
				intent_toPre.putExtra("isShowDialogTip", isShowDialogTip);
				intent_toPre.putExtra("enterTypeFlag", enterTypeFlag);
				intent_toPre.putExtra("title", title);
				intent_toPre.putExtra("surplus", surplus);
				intent_toPre.putExtra("yuebaoid", yuebaoid);
				intent_toPre.putExtra("lowestAmount", lowestAmount);
				intent_toPre.putExtra("rates", rates);
				intent_toPre.putExtra("interests", interests);
				intent_toPre.putExtra("url_xieYi", url_xieYi);
				intent_toPre.putExtra("title_xieYi", title_xieYi);
				startActivity(intent_toPre);
			} else if (enterTypeFlag == 5) {
				intent_toPre = new Intent(mContext, TenderAffirmActivity.class);
				intent_toPre.putExtra("isShowDialogTip", isShowDialogTip);
				intent_toPre.putExtra("enterTypeFlag", enterTypeFlag);
				intent_toPre.putExtra("bidId", bidId);
				intent_toPre.putExtra("bidTitle", bidTitle);
				intent_toPre.putExtra("bidPeriod", bidPeriod);
				intent_toPre.putExtra("amountMultiple", amountMultiple);
				intent_toPre.putExtra("lowestAmount", lowestAmount);
				intent_toPre.putExtra("bidPeriodType", bidPeriodType);
				intent_toPre.putExtra("bidInterest", bidInterest);
				intent_toPre.putExtra("bidFreeAmount", bidFreeAmount);
				intent_toPre.putExtra("maxAmount", maxAmount);
				intent_toPre.putExtra("bidAmount", bidAmount);
				intent_toPre.putExtra("totalLixi", totalLixi);
				intent_toPre.putExtra("bidType", bidType);
				intent_toPre.putExtra("businessType", businessType);
				intent_toPre.putExtra("productType", productType);
				intent_toPre.putExtra("bidPeriodWeb", bidPeriodWeb);
				intent_toPre.putExtra("bidPeriodAdd", bidPeriodAdd);
				if ("501".equals(bidType)
						&& PreferenceUtils.getInstance()
								.getKkxfStatus(mContext) == 0) {// 为体验标并且没有快快享福特权
					AppUtil.makeToastForCustomer(mContext, PreferenceUtils
							.getInstance().getKkxfExt(mContext));
				} else {
					mContext.startActivity(intent_toPre);
				}
			} else if (enterTypeFlag == 6) { // 债权转让购买
				intent_toPre = new Intent(mContext,
						CreditorIsRightsTenderAffirmActivity.class);
				intent_toPre.putExtra("json", json);
				startActivity(intent_toPre);
			}
			finish();
		}
	}

}
